const tool = {
	/* 拨打电话 */
	callPhone(phoneNum = '18563032777') {
		const phone = phoneNum
		const res = uni.getSystemInfoSync();
		// ios系统默认有个模态框
		if (res.platform == 'ios') {
			uni.makePhoneCall({
				phoneNumber: phone,
				success() {
					console.log('拨打成功了');
				},
				fail() {
					console.log('拨打失败了');
				}
			})
		} else {
			//安卓手机手动设置一个showActionSheet
			uni.showActionSheet({
				itemList: [phone, '呼叫'],
				success: function(res) {
					if (res.tapIndex == 1) {
						uni.makePhoneCall({
							phoneNumber: phone,
						})
					}
				}
			})
		}
	},
	/* home菜单数据表头type==1 */
	headTypeList: [{
			name: '规格',
			w: '20%'
		},
		{
			name: '米数/1米',
			w: '20%'
		},
		{
			name: '单价',
			w: '20%'
		},
		{
			name: '米数/1.2米',
			w: '20%'
		},
		{
			name: '单价',
			w: '20%'
		}
	],
	/* home菜单数据表头type==3 */
	headType2List: [{
			name: '规格',
			w: '25%'
		},
		{
			name: '米数/件',
			w: '25%'
		},
		{
			name: '单价/平方米',
			w: '25%'
		},
		{
			name: '价格/件',
			w: '25%'
		}
	],
	/* 设置价格涨跌数据颜色 */
	setUpDownColor(val, color = "#000") {
		let resColor = color
		let value = Number(val)
		if (val > 0) {
			resColor = "#be4f47"
		} else if (val < 0) {
			resColor = "#69ad76"
		}
		return resColor
	},
	/* 设置处理价格涨跌数据 */
	setUpDownData(val, sign = true) {
		if (val === "" || val === null) return
		let value = Number(val)
		if (value > 0) {
			return `+${value}`
		}
		return value
	},
	handleCommentDate(date) {
		const inputDate = new Date(date);
		const today = new Date();
		const yesterday = new Date(today);
		yesterday.setDate(today.getDate() - 1);

		// 比较年月日
		const isToday = inputDate.getFullYear() === today.getFullYear() &&
			inputDate.getMonth() === today.getMonth() &&
			inputDate.getDate() === today.getDate();

		const isYesterday = inputDate.getFullYear() === yesterday.getFullYear() &&
			inputDate.getMonth() === yesterday.getMonth() &&
			inputDate.getDate() === yesterday.getDate();
		const date1 = tool.formatDateTime(date)
		if (isToday) {
			return date1.slice(-8,-3);
		} else if (isYesterday) {
			return "昨天";
		} else {
		    return date1
		}
	},
	formatDateTime(val) {
		const date = new Date(val)
	    const year = date.getFullYear().toString().slice(0); // 获取年份后两位
	    const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份，补零
	    const day = date.getDate().toString().padStart(2, '0'); // 获取日期，补零
	    const hours = date.getHours().toString().padStart(2, '0'); // 获取小时，补零
	    const minutes = date.getMinutes().toString().padStart(2, '0'); // 获取分钟，补零
	    const seconds = date.getSeconds().toString().padStart(2, '0'); // 获取秒数，补零
	    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 返回 YY-MM-DD HH:mm:ss 格式
	}
}


export default tool